package pub.wkq.user.controller;


import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pub.wkq.bo.CreateAdminBO;
import pub.wkq.bo.ResetPwdBO;
import pub.wkq.common.base.BaseInfoProperties;
import pub.wkq.common.result.JSONResult;
import pub.wkq.user.service.AdminService;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 慕聘网运营管理系统的admin账户表，仅登录，不提供注册 前端控制器
 * </p>
 *
 * @author 王开琦
 * @since 2023-06-05
 */
@RestController
@RequestMapping("admininfo")
public class AdminInfoController extends BaseInfoProperties {
    @Resource
    private AdminService adminService;

    /**
     * <h2>admin 用户创建 </h2>
     */
    @RequestMapping("/create")
    public JSONResult createAdmin(@Valid @RequestBody CreateAdminBO createAdminBO) {
        adminService.createAdmin(createAdminBO);
        return JSONResult.ok();
    }
    @PostMapping("/list")
    public JSONResult listAdmin(String accountName,
                                Integer page,
                                Integer limit) {
        if (page == null || page < 1) {
            page = 1;
        }
        if (limit == null || limit < 1) {
            limit = 10;
        }
        return JSONResult.ok(adminService.list( accountName, page, limit));
    }

    @PostMapping("/delete")
    public JSONResult deleteAdmin(String username) {
        if (username == null) {
            return JSONResult.errorMsg("用户名不能为空");
        }
        adminService.deleteAdmin(username);
        return JSONResult.ok();
    }
    @PostMapping("/resetPwd")
    public JSONResult resetPwd(@Valid @RequestBody ResetPwdBO resetPwdBO) {
        adminService.resetPwd(resetPwdBO);
        return JSONResult.ok();
    }
}

